#!/bin/bash
set -e;


whoname=`whoami`
sudo mkdir -p /opt/samba;sudo chmod -R 755 /opt/samba;
sudo chown -R ${whoname} /opt/samba;
sudo apt install samba samba-client -y;
cp st*.sh /opt/samba/;
sudo chmod 755 /opt/samba/*;




if [ -e /opt/samba/smb.conf ]; then
    echo "There is having /opt/samba/smb.conf  , ignore init smb.conf !"
    echo "stop services.....";
    sudo systemctl stop smbd;
	echo "start services......"
	sudo systemctl enable --now smbd;
else
    sudo ln -s /etc/samba/smb.conf  /opt/samba/smb.conf;

    ## 添加smb1 协议支持
    sudo sed -i '/\[global\]/a\\   client min protocol = NT1' /etc/samba/smb.conf;

    sudo sed -i '/\[global\]/a\\   server min protocol = NT1' /etc/samba/smb.conf;



    sudo chmod 755 /opt/samba/*;
    sudo systemctl enable --now smbd;
	echo "please config /opt/samba/smb.conf , then to start [sudo systemctl restart smbd]"

fi;


